package com.itheima.edu.info.manager.dao;

import com.itheima.edu.info.manager.domain.Student;

public class StudentDao {
    public Student[]stus= new Student[5];
    /**
     * 增加
     * @param stu
     * @return
     */
    public boolean addStudent(Student stu) {

        int index=-1;
        for (int i = 0; i < stus.length; i++) {
            Student student = stus[i];
            if (student==null){
                index=i;
                break;
            }
        }
        if (index==-1){
            return false;
        }else {
            stus[index]=stu;
            return true;
        }
    }

    public Student[] findAllStudent() {
        return stus;
    }

    public void deleteStudentById(String delId) {
        int index = getIndex(delId);
        stus[index]=null;
    }
    public int getIndex(String id){
        int index=-1;
        for (int i = 0; i < stus.length; i++) {
            Student student = stus[i];
            if (student!=null&&student.getId().equals(id)){
                index=i;
                break;
            }
        }
        return index;
    }

    public void updateStudent(String updateId, Student newStu) {
        int index = getIndex(updateId);
        stus[index]=newStu;
    }
}
